<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><spring:message code="message.list.qiYeChanPinXinXiTianJiaXiuGai"/></title>

<%@ include file="/WEB-INF/component/commonCSS.jsp" %> 
<style type="text/css">
    	div.box-body {
    		margin-top:7px;
    	}
    </style>

</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>${(opType==0)?"药品新增":"药品编辑"}</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#">不竞不限目录维护</a></li>
        </ol>
    </section>
    <section class="content">
       <form  id="form1" class="form-horizontal" action="${ctx}/stdProdDrugInfo/saveDrugNoJNoXData.html" method="post">
           <%-- <input type="hidden" name="prodId" value="${detail.prodId}" />
           <input type="hidden" name="opType" value="${opType}" />
           <input type="hidden" name="status" value="${detail.status}" />
           <input type="hidden" id="prodCompId" name="prodCompId" value="${detail.prodCompId }">
           <input type="hidden" id="prodCompCode" name="prodCompCode" value="${detail.prodCompCode }">
           <input type="hidden" id="prodCompStatus" name="prodCompStatus" value="${detail.prodCompStatus }">
           <input type="hidden" id="unitStatus" name="unitStatus" value="${detail.unitStatus }">  
           <input type="hidden" id="materialCode" name="materialCode" value="${detail.materialCode }">
           <input type="hidden" id="materialStatus" name="materialStatus" value="${detail.materialStatus }">
           <input type="hidden" id="pharId" name="pharId" value="${detail.pharId }">
           <input type="hidden" id="pharCode" name="pharCode" value="${detail.pharCode }">
           <input type="hidden" id="pharStatus" name="pharStatus" value="${detail.pharStatus }">
           <input type="hidden"  name="drugCode" value="${detail.drugCode }"> --%>
        <div class=" box box-success">
        	 <div class="box-header with-border">
                 <h3 class="box-title"><spring:message code="message.listForm.YaoPinXinXi"/><spring:message code="message.yanZheng.maoHao"/>
                 </h3>
                 </div>
                <div class="box-body">
                
                 <div class="form-group form-group-xs">
                       <label class="col-sm-2 text-right"><span class="required">*</span><spring:message code="message.listForm.shengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                             <input type="hidden" id="prodCompCode" name="prodCode">
                             <input type="hidden" id="prodCompId" name="prodCompId" >
           					 <input type="hidden" id="prodCompStatus" name="prodCompStatus">
                            <input onclick="prodComp(1);" class="form-control" readonly="readonly" id="prodCompName" name="prodName" placeholder="<spring:message code="message.listForm.shengChanQiYe"/>" value="${detail.prodCompName }" type="text">
                        </div>
                        
                        <label class="col-sm-3 text-right"><span class="required">*</span><spring:message code="message.model.peiSongQiYe"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                             <input type="hidden" id="delCompCode" name="delCode">
                            <input onclick="prodComp(2);" class="form-control" readonly="readonly" id="delCompName" name="delName" placeholder="<spring:message code="message.model.peiSongQiYe"/>" value="${detail.Name }" type="text">
                        </div>
                    </div>
                
                   <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span><spring:message code="message.listForm.danWei"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                          <input type="hidden" id="unit" name="unitId" >
                          <input type="hidden" id="unitCode" name="unitCode" > 
                            <input onclick="stdUnit();" class="form-control" readonly="readonly" id="unitName" name="packUnitName" placeholder="<spring:message code="message.listForm.danWei"/>" value="${detail.unitName }" type="text">
                        </div>
                    </div>
                
	                <div class="form-group form-group-xs">
                       <label class="col-sm-2 text-right"><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="drugCode" name="drugCode"  placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>" type="text" maxlength="20">
                        </div> 
                        
                        <label class="col-sm-3 text-right"><span class="required">*</span><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                            <input onclick="quality();" class="form-control" readonly="readonly" id="qualityspecName" name="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>" type="text" value="${detail.qualityspecName}">
                        </div>
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span><spring:message code="message.listForm.jiXing"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                            <input onclick="quality();" class="form-control" readonly="readonly" id="formName" name="drugForm" placeholder="<spring:message code="message.listForm.jiXing"/>" type="text" value="${detail.formName}" >
                        </div>
                        
                        <label class="col-sm-3 text-right"><span class="required">*</span><spring:message code="message.listForm.guiGe"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                            <input type="hidden" id="qualityspecId" name="qualityspecId">
                            <input type="hidden" id="remark" name="remark">
                             <input type="hidden" id="dicName" name="dicName">
                            <input onclick="quality();" class="form-control" readonly="readonly" id="specName" name="spec" placeholder="<spring:message code="message.listForm.guiGe"/>" type="text" value="${detail.specName}" >
                        </div>
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span><spring:message code="message.listForm.piZhunWenHao"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="approvalCode" name="approveCode" placeholder="<spring:message code="message.listForm.piZhunWenHao"/>" type="text" value="${detail.approvalCode }"  maxlength="20">
                        </div>
                    </div>
                   <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span><spring:message code="message.listForm.BaoZhuangShuLiang"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="packNum" name="num" placeholder="<spring:message code="message.listForm.BaoZhuangShuLiang"/>" type="text" value="${detail.approvalCode }"  maxlength="20">
                        </div>
                        
                        <label class="col-sm-3 text-right"><span class="required">*</span><spring:message code="message.listForm.JiaGe"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" id="price" name="price" placeholder="<spring:message code="message.listForm.JiaGe"/>" type="text" value="${detail.approvalCode }"  maxlength="20">
                        </div>
                    </div>
                     <div class="box-footer text-center">
                        <button type="button" onclick="save();" class="btn btn-success btn-sm"><spring:message code="message.button.saveSpacing"/></button>
                        <a href="${ctx}/purGoodsSelect/drugNoJNoXList.html" class="btn btn-danger btn-sm"><spring:message code="message.button.getBackSpacing"/></a>
                     </div>
                </div>
               </div>
          </form>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %> 
    <script type="text/javascript">
    
	     //保存
	     function save() {
	    	if (!validate()) {
                return;
            }  
            $.HN.message.confirm('<spring:message code="message.HN.alert.queDingYaoBaoCunMa"/>', '', '').on(function (e) {
               if (e) {
			            $("#form1").ajaxSubmit({
			                dataType : "json",
			                timeout: 10000,
			                success : function(result, statusText) {
			                    if (result.success) {
			                    	top.$.alert("<spring:message code="message.HN.alert.success"/>", "success");
			                    	document.location = "${ctx }/purGoodsSelect/drugNoJNoXList.html";
			                    } else {
			                        top.$.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
			                    }
			                }
			            });
                   }
              });
            
        }
	    
	  
	  
	  
	//通用名、剂型、规格弹窗
	  function quality(){
	        var url = "${ctx}/stdProdDrugInfo/toSelectQualityspec.html";
	      $.HN.dialog.open({
	          "id": "quality",
	          "title": "<spring:message code="message.lable.drugqualityspecStd"/>", 
	          "url": url, 
	          "data": {}, 
	          "width": 800, 
	          "height": 510, 
	          "closefunc":function(params) {
	              if (params) {
	            	  $("#qualityspecId").val(params.qualityspecId);
	                  $("#specName").val(params.specName);
	                  $("#formName").val(params.formName);
	                  $("#qualityspecName").val(params.qualityspecName);
	                  $("#qualityspecNameEng").val(params.qualityspecNameEng);
	                  $("#remark").val(params.remark);
	                  $("#dicName").val(params.dicName);
	              }
	          }
	      });   
	  }
	  
	//企业弹窗
	  function prodComp(obj) {
	       var url = "${ctx}/stdProdDrugInfo/toSelectComp.html?compType="+obj;
	      $.HN.dialog.open({
	          "id": "prodComp",
	          "title": "<spring:message code="message.lable.compXinXiKu"/>", 
	          "url": url, 
	          "data": {}, 
	          "width": 1000, 
	          "height": 540, 
	          "closefunc":function(params) {
	              if (params != null) {
 					  if(params.compType == 1){
 						  $("#prodCompName").val(params.compName);
 		                  $("#prodCompCode").val(params.compCode);
 		                  $("#prodCompId").val(params.prodCompId);
 		                  $("#prodCompStatus").val(params.prodCompStatus);
	            	  }
	            	  if(params.compType == 2){
	            		  $("#delCompName").val(params.compName);
		                  $("#delCompCode").val(params.compCode);
	            	  }
	              }
	          }
	      }); 
	  }
	
	   //药理分类 弹窗
      function dicPhar() {
           var url = "${ctx}/stdProdDrugInfo/toSelectPhar.html";
          $.HN.dialog.open({
              "id": "dicPhar",
              "title": "<spring:message code="message.lable.yaoLiFenLeiKu"/>", 
              "url": url, 
              "data": {}, 
              "width": 800, 
              "height": 510, 
              "closefunc":function(params) {
                  if (params) {
                      $("#pharName").val(params.pharName);
                      $("#pharId").val(params.pharId);
                      $("#pharCode").val(params.pharCode);
                      $("#pharStatus").val(params.pharStatus);
                  }
              }
          }); 
      }
  
    //材质  弹窗
      function material() {
           var url = "${ctx}/stdProdDrugInfo/toSelectMaterial.html";
          $.HN.dialog.open({
              "id": "material",
              "title": "<spring:message code="message.lable.caiZhiKu"/>", 
              "url": url, 
              "data": {}, 
              "width": 800, 
              "height": 510, 
              "closefunc":function(params) {
                  if (params) {
                      $("#materialName").val(params.materialName);
                      $("#materialId").val(params.materialId);
                      $("#materialCode").val(params.materialCode);
                      $("#materialStatus").val(params.materialStatus);
                  }
              }
          }); 
      }
    
      //单位  弹窗
      function stdUnit() {
           var url = "${ctx}/stdProdDrugInfo/toSelectUnit.html";
          $.HN.dialog.open({
              "id": "stdUnit",
              "title": "<spring:message code="message.lable.baoZhuangDanWeiKu"/>", 
              "url": url, 
              "data": {}, 
              "width": 800, 
              "height": 510, 
              "closefunc":function(params) {
                  if (params) {
                      $("#unitName").val(params.unitName);
                      $("#unit").val(params.unitId);
                      $("#unitCode").val(params.unitCode);
                      $("#unitStatus").val(params.unitStatus);
                  }
              }
          }); 
      }
      
      
      
    //效验
      function validate() {
    	
    	  var prodCompName = $.trim($("#prodCompName").val());
          if (prodCompName == null || prodCompName == "") {
              $.alert("<spring:message code="message.yanZheng.shengChanQiYeNotNull"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingDianJiTanChuangXuanZe"/>", "warn");
              return false;
          }
          
          var delCompName = $.trim($("#delCompName").val());
          if (delCompName == null || delCompName == "") {
              $.alert("<spring:message code="message.yanZheng.peisongQiYeNotNull"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingDianJiTanChuangXuanZe"/>", "warn");
              return false;
          }
          
          var unitName = $.trim($("#unitName").val());
          if (unitName == null || unitName == "") {
              $.alert("<spring:message code="message.yanZheng.danWeiNotNull"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingShuRu"/>", "warn");
              return false;
          }
          
          var drugCode = $.trim($("#drugCode").val());
          if (drugCode != null && drugCode != "") {
            if (!/^[a-zA-Z0-9_]+$/.test(drugCode)) {
		              $.alert("<spring:message code="message.yanZheng.yaoPinBianMaYouZiMuShuZiZuCheng"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
		              return false;
	              }else if (drugCode.length > 128) {
		              $.alert("<spring:message code="message.yanZheng.yaoPinBianMaBuNengChaoGuoXianZhi"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingChongXinShuRu"/>", "warn");
		              return false;
              } 
          }
          
          var qualityspecName = $.trim($("#qualityspecName").val());
          if (qualityspecName == null || qualityspecName == "") {
              $.alert("<spring:message code="message.yanZheng.tongYongMingNotNull"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingDianJiTanChuangXuanZe"/>", "warn");
              return false;
          }
          
          var formName = $.trim($("#formName").val());
          if (formName == null || formName == "") {
              $.alert("<spring:message code="message.yanZheng.jiXingNotNull"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingDianJiTanChuangXuanZe"/>", "warn");
              return false;
          }
          
          var specName = $.trim($("#specName").val());
          if (specName == null || specName == "") {
              $.alert("<spring:message code="message.yanZheng.guiGeNotNull"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingDianJiTanChuangXuanZe"/>", "warn");
              return false;
          }
          
          
          var approvalCode = $.trim($("#approvalCode").val());
          if (approvalCode == null || approvalCode == "") {
              $.alert("<spring:message code="message.yanZheng.piZhunWenHaoNotNull"/><spring:message code="message.yanZheng.ganTanHao"/><spring:message code="message.yanZheng.qingShuRu"/>", "warn");
              return false;
          }else if (approvalCode.length >100 ) {
              $.alert("<spring:message code="message.yanZheng.piZhunWenHaoChaoGuoXianZhi"/>", "warn");
              return false;
          }
          
          var packNum = $.trim($("#packNum").val());
          if (packNum == "" || packNum == null){
              $.HN.message.alert("请填写包装数量！", "消息", "warn");
              return false;
          }else if(!/^[0-9]+$/.test(packNum) || packNum < 0){
              $.HN.message.alert("包装数量要大于0的整数！", "消息", "warn");
              return false;
          }
          
          var price = $.trim($("#price").val());
          if (price == "") {
              $.HN.message.alert("请填写价格！", "消息", "warn");
              return false;
          } else if(/^[0-9]+$/.test(price)){
              price += ".00";
              $("#price").val(price);
          } else if(/^[0-9]+(.[0-9]{1})+$/.test(price)) {
              price += "0";
              $("#price").val(price);
          } else if(!/^[0-9]+(.[0-9]{2})+$/.test(price)) {
              $.HN.message.alert("请填写正确的价格！", "消息", "warn");
              return false;
          }
          
          return true;
      }
	   
    </script>
</body>
</html>